<template>
  <div class="event-list">
    <el-button class="add-event-button" type="primary" @click="dialogVisible = true" icon="el-icon-plus" circle></el-button>
    <el-dialog title="添加事件" :visible.sync="dialogVisible" width="600px">
      <EventEditer @success="getEevents" />
    </el-dialog>

    <el-table :data="data">
      <el-table-column type="index" width="50" />
      <el-table-column prop="description" label="时间">
      </el-table-column>
      <el-table-column prop="score" label="加分" sortable width="150">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDeleteButtonClick(scope.row.id)">移除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current" :page-sizes="[8, 16, 32, 999]" :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination> -->
  </div>
</template>

<script>
import api from "@/api";
import EventEditer from "./EventEditer";

export default {
  components: {
    EventEditer
  },
  data() {
    return {
      dialogVisible: false,
      data: []
    };
  },
  created() {
    this.getEevents();
  },
  methods: {
    async getEevents() {
      const { data } = await api.getEvents();
      this.data = data.data;
    },
    async handleDeleteButtonClick(id) {
      const { data } = await api.deleteEvent({
        id
      });
      this.getEevents();
    }
  }
};
</script>

<style lang="scss" scoped>
.add-event-button {
  position: absolute;
  right: 8vw;
  bottom: 10vh;
  z-index: 100;
  transform: scale(2);
}
</style>
